package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单管理接口")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto){
            log.info("订单搜索：{}", dto);
            PageResult pageResult = ordersService.pageAdmin(dto);
            return Result.success(pageResult);
    }

    /**
     * 各个订单的订单数量统计
     * @return
     */
    @ApiOperation("各个订单的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("各个订单的订单数量统计");
        OrderStatisticsVO orderStatisticsVO = ordersService.countByStatus();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询订单详情
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("查询订单详情：{}",id);
        OrderVO orderVO = ordersService.getById(id);
        return Result.success(orderVO);
    }

    /**
     * 商家接单
     * @return
     */
    @ApiOperation("商家接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
            log.info("商家接单：{}",dto);
            ordersService.confirm(dto);
            return Result.success();
    }

    /**
     * 商家拒单
     * @return
     */
    @ApiOperation("商家拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        log.info("商家拒单:{}",dto);
        ordersService.rejetion(dto);
        return Result.success();
    }

    /**
     * 取消订单(管理端)
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        log.info("取消订单:{}",dto);
        ordersService.cancelAdmin(dto);
        return Result.success();
    }

    /**
     * 派送订单
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("派送订单:{}",id);
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
      log.info("完成订单:{}",id);
        ordersService.complete(id);
        return Result.success();
    }
}
